home *** CD-ROM | disk | FTP | other *** search
- package symantec.itools.db.awt;
-
- import java.awt.Event;
- import java.awt.FontMetrics;
- import java.awt.Graphics;
- import java.awt.Image;
- import java.awt.Rectangle;
- import java.awt.image.ImageObserver;
-
- public class BasicCell implements TableCell, ImageObserver {
- Grid view;
- DataSource dataSource;
- Coordinate coords;
- boolean selected;
- boolean keyPressedYet;
- boolean loseFocusOnArrow;
- int cursorPos;
- int hlFirst;
- int hlLast;
- boolean selectionMade;
- int offset;
- int chopIndex;
- int toLeftOfCell;
- int startX;
- boolean defaultCell;
- int type;
- static final int PADSIDES = 5;
-
- public BasicCell(Grid var1, DataSource var2) {
- this.view = var1;
- this.dataSource = var2;
- }
-
- public TableCell cloneCell() {
- BasicCell var1 = new BasicCell(this.view, this.dataSource);
- if (this.coords != null) {
- var1.coords = new Coordinate(this.coords.row, this.coords.col);
- }
-
- var1.selected = this.selected;
- var1.keyPressedYet = this.keyPressedYet;
- var1.loseFocusOnArrow = this.loseFocusOnArrow;
- var1.cursorPos = this.cursorPos;
- var1.selectionMade = this.selectionMade;
- var1.offset = this.offset;
- var1.type = this.type;
- return var1;
- }
-
- public int type() {
- return this.type;
- }
-
- public int type(int var1) {
- if (var1 <= 3 && var1 >= 0) {
- return this.type = var1;
- } else {
- throw new IllegalArgumentException("Invalid cell type");
- }
- }
-
- public void setGrid(Grid var1, DataSource var2) {
- this.view = var1;
- this.dataSource = var2;
- }
-
- public void setDefaultFlag() {
- this.defaultCell = true;
- }
-
- public void reset() {
- this.selected = false;
- this.keyPressedYet = false;
- this.loseFocusOnArrow = false;
- this.cursorPos = 0;
- this.selectionMade = false;
- this.offset = 0;
- }
-
- public boolean isCellTypeEditable() {
- return true;
- }
-
- public void setCoordinates(Coordinate var1) {
- this.coords = var1;
- }
-
- public Coordinate getCoordinates() {
- return this.coords;
- }
-
- public int row() {
- return this.coords.row;
- }
-
- public void setRow(int var1) {
- this.coords.row = var1;
- }
-
- public int col() {
- return this.coords.col;
- }
-
- public void setCol(int var1) {
- this.coords.col = var1;
- }
-
- public boolean mouseEvent(Event var1) {
- try {
- switch (var1.id) {
- case 63:
- this.keyPressedYet = false;
- this.view.redrawCell(this);
- this.offset = 0;
- this.view.generateEvent(var1, 63, this);
- break;
- case 501:
- if (!var1.shiftDown()) {
- this.keyPressedYet = true;
- this.view.setCapture();
- this.cursorPos = this.findCursorPos(var1.x);
- this.selectionMade = false;
- } else {
- this.hlFirst = this.cursorPos;
- this.hlLast = this.findCursorPos(var1.x);
- this.selectionMade = true;
- }
-
- this.view.redrawCell(this);
- this.view.generateEvent(var1, 61, this);
- break;
- case 502:
- this.view.generateEvent(var1, 60, this);
- break;
- case 506:
- if (!this.selectionMade && this.findCursorPos(var1.x) != this.cursorPos) {
- this.hlFirst = this.cursorPos;
- this.selectionMade = true;
- }
-
- this.hlLast = this.cursorPos = this.findCursorPos(var1.x);
- this.view.redrawCell(this);
- this.view.generateEvent(var1, 62, this);
- }
- } catch (DataNotAvailable var3) {
- this.view.handleException(this.row(), this.col(), var3);
- }
-
- return true;
- }
-
- int findCursorPos(int var1) throws DataNotAvailable {
- if (var1 < -this.offset) {
- return 0;
- } else {
- int var2 = this.offset + var1;
- FontMetrics var3 = this.view.getCellFontMetrics(this);
- Data var4 = this.readData();
- String var5 = var4.toString();
- int var6 = var5.length();
- Image var7 = var4.toImage();
- int var8 = this.view.getCellAlignment(this);
- if (var8 == 0) {
- if (this.offset == 0) {
- var2 -= 7;
- if (var7 != null) {
- int var9 = var7.getWidth(this) + 2;
- int var10 = this.view.getColumnWidth(this.getCoordinates().col);
- int var11 = var3.stringWidth(var5);
- if (var9 + var11 + 2 + 5 <= var10) {
- var2 -= var9;
- }
- }
- }
- } else if (var8 == 2) {
- int var12 = var3.stringWidth(var5);
- int var15 = this.view.getColumnWidth(this.getCoordinates().col);
- if (var12 <= var15 - 10) {
- var2 = var2 - var15 + var12 + 5;
- }
- } else if (var8 == 1) {
- int var13 = var3.stringWidth(var5);
- int var16 = this.view.getColumnWidth(this.getCoordinates().col);
- if (var13 <= var16) {
- var2 -= (var16 - var13) / 2;
- }
- }
-
- if (var2 <= 0) {
- return 0;
- } else {
- for(int var14 = 1; var14 <= var6; ++var14) {
- if (var3.stringWidth(var5.substring(0, var14 - 1) + var3.charWidth(var5.charAt(var14 - 1)) / 2) > var2) {
- return var14;
- }
- }
-
- return var6;
- }
- }
- }
-
- public Data getData() throws DataNotAvailable {
- return this.dataSource.getData(this.coords);
- }
-
- public Data readData() throws DataNotAvailable {
- return this.dataSource.readData(this.coords.row, this.coords.col);
- }
-
- void deleteChar(Data var1) {
- if (this.cursorPos != 0) {
- var1.deleteChar(this.cursorPos);
- --this.cursorPos;
- }
- }
-
- void deleteSelection(Data var1) {
- int var2 = Math.min(this.hlFirst, this.hlLast);
- int var3 = Math.max(this.hlFirst, this.hlLast);
-
- for(int var4 = var2; var4 < var3; ++var4) {
- var1.deleteChar(var2 + 1);
- }
-
- this.cursorPos = var2;
- }
-
- public boolean keyEvent(Event var1) {
- Data var2;
- try {
- var2 = this.getData();
- } catch (DataNotAvailable var9) {
- this.view.handleException(this.row(), this.col(), var9);
- return true;
- }
-
- char var3 = (char)var1.key;
- boolean var4 = false;
- boolean var5 = false;
- boolean var6 = var2.isEditable(this.coords.row, this.coords.col) && this.view.getCellEditable(this);
- if (var6 || var1.id != 403 && var1.id != 401) {
- if (!var6 && var1.id == 402) {
- return this.view.generateEvent(var1, 59, this);
- } else if (var1.id == 403) {
- if (var1.shiftDown() && !this.selectionMade) {
- this.selectionMade = true;
- this.hlFirst = this.hlLast = this.cursorPos;
- } else if (!var1.shiftDown()) {
- this.selectionMade = false;
- }
-
- switch (var3) {
- case 'Ϩ':
- case 'Ϭ':
- if (this.cursorPos != 0) {
- this.cursorPos = 0;
- var4 = true;
- }
- break;
- case 'ϩ':
- case 'ϭ':
- int var7 = var2.toString().length();
- if (this.cursorPos != var7) {
- this.cursorPos = var7;
- var4 = true;
- }
- case 'Ϫ':
- case 'ϫ':
- default:
- break;
- case 'Ϯ':
- if (this.cursorPos > 0) {
- --this.cursorPos;
- var4 = true;
- }
- break;
- case 'ϯ':
- if (this.cursorPos < var2.toString().length()) {
- ++this.cursorPos;
- var4 = true;
- }
- }
-
- if (this.selectionMade) {
- this.hlLast = this.cursorPos;
- }
-
- if (var4) {
- this.view.redrawCell(this);
- }
-
- return this.view.generateEvent(var1, 58, this);
- } else {
- if (var1.id == 401) {
- if (!this.keyPressedYet) {
- if (var1.key < 33 || var1.key > 122) {
- return this.view.generateEvent(var1, 58, this);
- }
-
- var2.clearText();
- var2.appendChar(var3);
- this.keyPressedYet = true;
- this.view.setCapture();
- this.cursorPos = 1;
- } else {
- if (this.selectionMade) {
- this.deleteSelection(var2);
- this.selectionMade = false;
- if (var3 == '\b' || var3 == 127) {
- return this.view.generateEvent(var1, 58, this);
- }
- }
-
- if (var1.key == 27) {
- this.cursorPos = 0;
- this.keyPressedYet = false;
- var5 = this.view.generateEvent(var1, 54, this);
- } else if (var3 == '\b') {
- this.deleteChar(var2);
- var5 = this.view.generateEvent(var1, 57, this);
- } else if (var3 == '\n') {
- try {
- this.dataSource.commitData();
- } catch (Exception var8) {
- this.view.handleException(this.row(), this.col(), var8);
- }
- } else if (var3 == 127) {
- if (this.cursorPos != var2.toString().length()) {
- ++this.cursorPos;
- this.deleteChar(var2);
- var5 = this.view.generateEvent(var1, 57, this);
- }
- } else if (this.cursorPos == var2.toString().length()) {
- var2.appendChar(var3);
- ++this.cursorPos;
- var5 = this.view.generateEvent(var1, 57, this);
- } else {
- var2.insertChar(this.cursorPos, var3);
- ++this.cursorPos;
- }
- }
-
- this.view.redrawCell(this);
- var5 |= this.view.generateEvent(var1, 58, this);
- } else if (var1.id == 402) {
- this.view.generateEvent(var1, 59, this);
- }
-
- return var5;
- }
- } else {
- return this.view.generateEvent(var1, 58, this);
- }
- }
-
- public boolean loseFocusOnArrow() {
- return this.selected & !this.keyPressedYet;
- }
-
- public void activateCursor() {
- this.selected = true;
- this.view.redrawCell(this);
- }
-
- public void deactivateCursor() {
- this.selected = false;
- this.view.redrawCell(this);
- }
-
- public boolean canLoseFocus() {
- try {
- this.dataSource.commitData();
- return true;
- } catch (Exception var2) {
- this.view.handleException(this.row(), this.col(), var2);
- return false;
- }
- }
-
- public boolean focusEvent(Event var1) {
- if (var1.id == 1004) {
- this.selected = true;
- this.view.generateEvent(var1, 55, this);
- this.view.redrawCell(this);
- } else {
- this.selected = false;
- this.keyPressedYet = false;
- this.selectionMade = false;
- this.offset = 0;
- this.cursorPos = 0;
- this.view.generateEvent(var1, 56, this);
-
- try {
- this.dataSource.commitData();
- } catch (Exception var3) {
- this.view.handleException(this.row(), this.col(), var3);
- }
-
- this.view.redrawAroundCell(this);
- }
-
- return true;
- }
-
- public boolean actionEvent(Event var1) {
- this.keyPressedYet = false;
- this.view.redrawCell(this);
- this.offset = 0;
- return true;
- }
-
- public void drawCell(Graphics var1, CellHints var2) {
- Object var3;
- try {
- var3 = this.readData();
- } catch (DataNotAvailable var12) {
- this.view.handleException(this.row(), this.col(), var12);
- var3 = new ImageStringData(this.dataSource, "");
- }
-
- Rectangle var4 = var2.bounds();
- FontMetrics var5 = this.view.getCellFontMetrics(this);
- var5.getAscent();
- int var6 = var5.stringWidth(((Data)var3).toString());
- int var7 = 0;
- int var8 = var4.x;
- int var9 = var4.width;
- var2.setBackground(var1);
- var1.fillRect(var4.x, var4.y, var4.width - 1, var4.height - 1);
- Image var10 = ((Data)var3).toImage();
- switch (var2.alignment()) {
- case 0:
- if (var10 != null) {
- var7 = var10.getWidth(this) + 2;
- }
-
- if (var7 + var6 + 2 + 5 <= var4.width && var10 != null) {
- var4.x += 5;
- ++var4.y;
- var1.drawImage(var10, var4.x, var4.y, this);
- --var4.y;
- } else {
- var7 = 0;
- }
-
- var4.x = var8 + var7 + 5;
- break;
- case 1:
- if (var6 > var4.width - 10) {
- var4.x += 5;
- } else {
- var4.x += (var4.width - var6) / 2;
- }
- break;
- case 2:
- if (var10 != null) {
- var7 = var10.getWidth(this);
- }
-
- if (var7 + 2 + var6 + 10 + 3 <= var4.width && var10 != null) {
- var4.x = var4.x + var4.width - var6 - var7 - 2 - 5 - 3;
- ++var4.y;
- var1.drawImage(var10, var4.x, var4.y, this);
- --var4.y;
- var4.x = var8 + var4.width - var6 - 5 - 3;
- } else {
- var7 = 0;
- if (var6 > var4.width - 10) {
- var4.x += 5;
- } else {
- var4.x = var8 + var4.width - var6 - 5 - 3;
- }
- }
- }
-
- var2.setForeground(var1);
- var4.width = var4.width + var8 - var4.x - 5;
- this.startX = var4.x;
- this.drawText((Data)var3, var1, var4, var5, var2);
- var4.width = var9;
- if (this.selected && this.keyPressedYet) {
- int var11 = 0;
- if (((Data)var3).toString().length() > 0) {
- var11 = var5.stringWidth(((Data)var3).subString(this.toLeftOfCell, this.cursorPos));
- }
-
- var1.drawLine(var4.x + var11, var4.y + 2, var4.x + var11, var4.y + var5.getHeight());
- }
-
- var4.x = var8;
- var2.drawBoundary(var1);
- }
-
- protected String chopString(Data var1, Rectangle var2, FontMetrics var3) {
- String var4 = var1.toString();
- int var5 = this.view.getColumnWidth(this.coords.col);
- this.chopIndex = 1;
- if (var4.length() == 0) {
- return var4;
- } else {
- this.setOffset(var4, var2, var3);
- if (this.offset == 0) {
- this.toLeftOfCell = 0;
- } else {
- while(this.toLeftOfCell < var4.length()) {
- int var7 = var3.stringWidth(var4.substring(0, this.toLeftOfCell));
- if (var7 >= this.offset + 5) {
- --this.toLeftOfCell;
- break;
- }
-
- ++this.toLeftOfCell;
- }
-
- this.toLeftOfCell -= this.toLeftOfCell < var4.length() ? 0 : 1;
- var4 = var4.substring(this.toLeftOfCell, var4.length());
- }
-
- String var6;
- do {
- var6 = var4.substring(0, this.chopIndex);
- } while(var3.stringWidth(var6) < var5 - 10 && this.chopIndex++ < var4.length());
-
- return var4.substring(0, --this.chopIndex);
- }
- }
-
- protected void drawText(Data var1, Graphics var2, Rectangle var3, FontMetrics var4, CellHints var5) {
- String var6 = this.chopString(var1, var3, var4);
- if (this.selected && !this.keyPressedYet) {
- var5.setForeground(var2);
- var2.fillRect(var3.x - 1, var3.y + 3, var4.stringWidth(var6.toString()) + 4, var4.getHeight() - 1);
- var5.setBackground(var2);
- var2.drawString(var6, var3.x, var3.y + var4.getAscent() + 2);
- } else if (this.selected && !this.selectionMade) {
- var2.drawString(var6, var3.x, var3.y + var4.getAscent() + 2);
- } else if (this.selected && this.selectionMade) {
- int var7 = Math.min(this.hlFirst, this.hlLast);
- int var8 = Math.max(this.hlFirst, this.hlLast);
- var8 = Math.min(var8, this.chopIndex);
- if (this.toLeftOfCell != 0) {
- var7 = Math.max(this.hlFirst, this.toLeftOfCell);
- }
-
- String var9 = var6.substring(0, var7);
- var2.drawString(var9, var3.x, var3.y + var4.getAscent() + 2);
- int var10 = var4.stringWidth(var9) + var3.x - this.offset;
- var9 = var6.substring(var7, var8);
- int var11 = var4.stringWidth(var9) + var10;
- var5.setForeground(var2);
- var2.fillRect(var10, var3.y + 2, var11 - var10, var4.getHeight() - 1);
- var5.setBackground(var2);
- var2.drawString(var9, var10, var3.y + var4.getAscent() + 2);
- var5.setForeground(var2);
- var9 = var6.substring(var8, var6.length());
- var2.drawString(var9, var11, var3.y + var4.getAscent() + 2);
- } else {
- var2.drawString(var6, var3.x, var3.y + var4.getAscent() + 2);
- }
- }
-
- void setOffset(String var1, Rectangle var2, FontMetrics var3) {
- String var4 = var1.substring(0, this.cursorPos);
- int var5 = var3.stringWidth(var4);
- byte var6 = 3;
- if (!this.selected) {
- this.offset = 0;
- } else if (var5 > var2.width - var6) {
- this.offset = -var2.width + var5 + var6;
- } else {
- this.offset = 0;
- }
- }
-
- int textLeft(int var1, Rectangle var2) {
- switch (this.view.getCellAlignment(this)) {
- case 0:
- default:
- return var2.x + 5;
- case 1:
- if (var1 > var2.width) {
- return var2.x;
- }
-
- return var2.x + (var2.width - var1) / 2;
- case 2:
- return var1 > var2.width ? var2.x + 5 : var2.x + var2.width - var1 - 5;
- }
- }
-
- public boolean imageUpdate(Image var1, int var2, int var3, int var4, int var5, int var6) {
- if ((var2 & 192) != 0) {
- return false;
- } else if ((var2 & 32) != 0) {
- this.view.redrawAsync();
- return false;
- } else {
- return true;
- }
- }
-
- public String toString() {
- try {
- return this.readData().toString();
- } catch (DataNotAvailable var1) {
- return "ERROR getting data";
- }
- }
-
- public String stats() {
- try {
- return "BasicCell: row=" + this.coords.row + " col=" + this.coords.col + " text=" + this.readData().toString();
- } catch (DataNotAvailable var1) {
- return "BasicCell: row=" + this.coords.row + " col=" + this.coords.col + " could not retrieve data";
- }
- }
- }
-